package com.itheima.controller.admin;

import com.itheima.common.entity.Result;
import com.itheima.dto.OrderSettingDTO;
import com.itheima.service.OrderSettingService;
import com.itheima.vo.OrderSettingVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 预约设置管理
 */
@RestController
@RequestMapping("/ordersetting")
@Slf4j
public class OrderSettingController {
  @Autowired
  private OrderSettingService orderSettingService;

  /**
   * 导出运营数据
   * @param response
   */
  @GetMapping("/download")
  public void download(HttpServletResponse response,@RequestParam String filename) {
     orderSettingService.exportBusinessData(response,filename);
  }
  /**
   *根据日期修改可预约人数
   */
  @PostMapping("/editNumberByOrderDate")
  public Result editNumberByOrderDate(@RequestBody OrderSettingDTO orderSettingDTO) {
    log.info("根据日期修改可预约人数:{}", orderSettingDTO);
    orderSettingService.updateNumberByOrderDate(orderSettingDTO);
    return Result.success("预约设置成功");
  }

    /**
     * 根据年月查询对应的预约设置信息
     * @param month
     * @return
     */
  @GetMapping("/getOrderSettingByMonth")
  public Result<List<OrderSettingVO>> getOrderSettingByMonth(@RequestParam String month) {
      List<OrderSettingVO> orderSettingsList= null;
      try {
          orderSettingsList = orderSettingService.getOrderInfoByMonth(month);
      } catch (Exception e) {
          throw new RuntimeException("请选择正确的年月");
      }
      return Result.success(orderSettingsList,"获取预约设置数据成功");
  }
  @PostMapping("/upload")
    public Result upload(@RequestBody MultipartFile excelFile) {
         orderSettingService.upload(excelFile);
      return  Result.success("预约设置成功");
  }
}
